<div class="modal fade " id="modifyTemplateParamModal"   role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">修改模板信息</h3>
            </div>

            <!-- form start -->
            <form class="form-horizontal" id="modifyTemplateParam" enctype="multipart/form-data">
                <div class="box-body">
                    <input id="rid" type="text" style="display:none;">
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="remarkLabel">备注</label>
                        <div class="col-sm-10">
                            <input id="mremark" type="text" class="form-control">
                        </div>
                    </div>
                    <table id="mreportDictTable" data-toggle="table" data-url="/reporttemplate/queryTemplateDictList"
                               data-click-to-select="true" data-single-select="false" width="20"
                               data-toolbar="toolbar" data-query-params="queryParams1" data-search="true"
                               data-pagination="true" data-page-size="4" data-sort-name="labelName" data-checkbox-header="false">
                        <thead>
                            <tr>
                                <th data-field="state"  data-checkbox="true">选择</th>
                                <th data-field="labelName" data-sortable="true">参数名</th>
                                <th data-field="paramName"  data-sortable="true">参数字段名</th>
                            </tr>
                        </thead>
                    </table>
                </div>
                <div class="box-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal"  >取消</button>

                    <button type="button" class="btn btn-primary pull-right" onclick="updateTemplateParam()">更新</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    //初始化修改页面
    function modifyTemplateParamInit(id, param, remark) {
        var paramItem= new Array();

        //参数名根据|拆分，将各个值设置到相应的text
        paramItem=param.split("|");

        for (i=0;i<paramItem.length ;i++ )
        {
            var rows = $("#mreportDictTable").bootstrapTable('getData', function (row) {
                              return row;
                    });


            if(rows.length > 0) {
                for(j=0; j<rows.length; j++){

                    rows[j].state = true;
                    rows[j].checked = true;
                    //$(rows[j]).find('input[name="btSelectItem"]').attr('checked',true);

                    //$(rows[j].sel).attr("checked",true);
                }

                //$('#state').get(0).checked = true;

                //$("#mreportDictTable").find(':checkbox').prop('checked',$(this).prop('checked'));


                 //var data = $('#mreportDictTable').DataTable().rows().nodes();
                 //var data2 = $('#mreportDictTable').DataTable().rows().data();
                 //$(data).each(function(index,row){
                 //   for(j=0; j<rows.length; j++){
                 //       if(data2[index].state==true){
                 //           data[index].addClass('selected');
                 //       }else{
                 //           data[index].removeClass('selected');
                 //       }
                 //   }
                 //});
            }
        }

        //设置备注
        $("#mremark").val(remark);

        //报表ID
        $("#rid").val(id);
    }

    function updateTemplateParam(){

        var paramValue = "";

        var rows = $("#reportDictTable").bootstrapTable('getSelections', function (row) {
                          return row;
        });

        if(rows.length > 0) {
            var data = $('#reportDictTable').bootstrapTable('getData');

            for(var i=0; i<rows.length; i++){
                if(paramValue.length == 0) {
                    paramValue = rows[i].paramName;
                } else {
                    paramValue = paramValue + "|" + rows[i].paramName;
                }
            }
        }


        var data = {
            id : $("#rid").val(),
            param : paramValue,
            remark : $("#mremark").val()
        }

        var url = "/reporttemplate/updatetemplateinfo";
        postReq(url, data, function (result) {
            if (result.success) {
                $("#modifyTemplateParamModal").modal("hide");
                $("#templateTable").bootstrapTable("refresh");
                toastr['success']('更新模板信息成功', '提示');
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }
</script>